﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Test
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void btnRegister_Click(object sender, EventArgs e)
        {
            //获取画面数据
            string name = txbName.Text;
            string pwd = txbPwd.Text;
            //判断
            if (name == "请输入用户名" || pwd == "请输入密码")
            {
                MessageBox.Show("用户名和密码不能为空！");
            }
            else if (name == "loginName")
            {
                MessageBox.Show("用户名已存在");
            }
            else
            {
                //创建sql语句

                string sqlAdd = string.Format("insert into test values ('{0}','{1}')", name, pwd);
                bool result = DBHelper.GetNonQuery(sqlAdd);
                if (result)
                {
                    MessageBox.Show("添加成功");
                }
                else
                {
                    MessageBox.Show("添加失败");
                }

            }
           
            

        }

        private void txbName_TextChanged(object sender, EventArgs e)
        {
         /*   //获取用户名长度
            int NameLength = this.txbName.Text.Trim().Length;
            if (!userNameMouseClick)//如果未触发事件
            {
                if (NameLength == 0)//如果用户名输入为空
                {
                    userName = true;
                    this.txbName.Text = "最少1位，最多10位";
                    this.txbName.Font = new Font("行楷", 9, FontStyle.Italic);
                    this.txbName.ForeColor = ColorTranslator.FromHtml("#8888888");
                }
            }*/
        }

        private void Form1_Load(object sender, EventArgs e)
        {
         /*   //用户名最多允许输入12位
            this.txbName.MaxLength = 12;
            //密码最少允许18位
            this.txbPwd.MaxLength = 18;
*/
        }
        //声明全局变量
        /*private bool userName = false;//标识用户名是否为空
        private bool userNameMouseClick = false;//标识用户名输入框是否触发事件
        private bool Pwd = false;//表示密码是否为空
        private bool PwdMouseClick = false;//标识密码输入是否触发*/
        private void txbName_MouseClick(object sender, MouseEventArgs e)
        {
            /*if (userName)
            {
                //标识触发事件
                userNameMouseClick = true;
                this.txbName.Text = "";
            }*/
        }

        private void txbName_Leave(object sender, EventArgs e)
        {
            /*//获取用户名长度
            int uNameLength = this.txbName.Text.Trim().Length;

            if (uNameLength == 0)
            {
                userName = true;
*/
            }

        }
    }

